package other;
/**
 * 
 */
public class BeanUtils {

	@SuppressWarnings("unchecked")
	public static <T> T instantiate(String className, Class<T> superClass){
		
		try {
			Class<?> clz = Class.forName(className);
			
			if (!superClass.isAssignableFrom(clz)){
				throw new RuntimeException("类"+className+"必须是"+superClass+"的子类/实现类");
			}
			
			return (T) instantiate(clz);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException("指定的类"+className+"无法找到");
		}
		
		
	}
	
	public static <T> T instantiate(Class<T> clazz) {
		Assert.notNull(clazz, "Class must not be null");
		if (clazz.isInterface()) {
			throw new RuntimeException("指定的类是接口");
		}
		try {
			return clazz.newInstance();
		}
		catch (InstantiationException ex) {
			throw new RuntimeException("是否抽象类?", ex);
		}
		catch (IllegalAccessException ex) {
			throw new RuntimeException("构造方法是否可访问?", ex);
		}
	}
	
}
